package com.example.goband.common;


import com.example.goband.model.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 当前登录用户相关操作
 */
public class UserSessionUtils {

    public static User getUserBySession(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if(session != null && session.getAttribute(AppVariable.USER_SESSION_KEY) != null) {
            //返回用户信息
            return (User) session.getAttribute(AppVariable.USER_SESSION_KEY);
        } else {
            //用户未登录
            return null;
        }
    }

}
